#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <process.h>
#include <Tlhelp32.h>
#include <string.h>
#ifndef MYBOOLEAN_H
#define MYBOOLEAN_H

#define false 0
#define true 1
typedef int bool; // or #define bool int

#endif

void sleep(unsigned int mseconds)
{
    clock_t goal = mseconds + clock();
    while (goal > clock());
}
bool ProcessRunning( const char* name )
{
	HANDLE SnapShot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );

	if( SnapShot == INVALID_HANDLE_VALUE )
		return false;

	PROCESSENTRY32 procEntry;
	procEntry.dwSize = sizeof( PROCESSENTRY32 );

	if( !Process32First( SnapShot, &procEntry ) )
		return false;

	do
	{
		if( strcmp( procEntry.szExeFile, name ) == 0 )
			return true;
	}
	while( Process32Next( SnapShot, &procEntry ) );

	return false;
}
void killProcessByName(const char *filename)
{
   HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);
    PROCESSENTRY32 pEntry;
    pEntry.dwSize = sizeof (pEntry);
    BOOL hRes = Process32First(hSnapShot, &pEntry);
    while (hRes)
    {
        if (strcmp(pEntry.szExeFile, filename) == 0)
        {
            HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, 0,(DWORD) pEntry.th32ProcessID);
            if (hProcess != NULL)
            {
                TerminateProcess(hProcess, 9);
                CloseHandle(hProcess);
                printf("Lullo_GOT_OWNED\n");
            }
        }
        hRes = Process32Next(hSnapShot, &pEntry);
    }
    CloseHandle(hSnapShot);
}
int main()
{
    char *italcClient = "ica.exe";
    char *italcManager = "imc.exe";
    char *italcDebug = "ima.exe"; //<- ? todo find this process
    if(ProcessRunning(italcClient)== 1)
   {
       printf("process found\n");
       killProcessByName("ica.exe");
   }


        //killProcessByName("imc.exe");
        //killProcessByName("ima.exe");


return 0;
}

